/*
 *  This file is part of Zetta-Core Engine <http://www.zetta-core.org>.
 *
 *  Zetta-Core is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published
 *  by the Free Software Foundation, either version 3 of the License,
 *  or (at your option) any later version.
 *
 *  Zetta-Core is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a  copy  of the GNU General Public License
 *  along with Zetta-Core.  If not, see <http://www.gnu.org/licenses/>.
 */
package gameserver.skill.properties;




import gameserver.model.gameobjects.Creature;
import gameserver.skill.effect.EffectId;
import gameserver.skill.model.Skill;

import java.util.EnumSet;

import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;


/**
 * @author Rolandas
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TargetStatusProperty")
public class TargetStatusProperty extends Property
{

	@XmlAttribute(name = "value", required = true)
	protected String stateSet;
	
	@XmlTransient
	protected EnumSet<EffectId> value = EnumSet.noneOf(EffectId.class);
	
	void afterUnmarshal(Unmarshaller u, Object parent)
	{
		if (stateSet == null || stateSet.isEmpty())
			return;

		String[] states = stateSet.split(" ");
		for (String state : states)
			value.add(EffectId.valueOf(state));

		stateSet = null;
	}
	
	@Override
	public boolean set(Skill skill)
	{
		if (skill.getEffectedList().size() != 1)
			return false;
		
		Creature effected = skill.getEffectedList().first().getCreature();
		boolean result = false;
		
		for (EffectId as : value)
		{
			if (effected.getEffectController().isAbnormalSet(as))
				result = true;
		}
		
		return result;
	}

}